package stu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import entity.Page;
import entity.stuCourse;
import stu.dao.StudentDaoImpl;

@WebServlet("/Fenye")
public class Fenye extends HttpServlet {
	
		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			HttpSession session = request.getSession();
			String number=request.getParameter("pageNum");
			int pageNum = 0;
			if(number==null || number.equals("")){
				pageNum=1;
			}else {
				pageNum=Integer.parseInt(number);	
			}
			StudentDaoImpl s = new StudentDaoImpl();
		
			List<stuCourse> page=s.findCourseByPage(pageNum,10);
			
			int count = s.findCount();
			Page<stuCourse> p=new Page<stuCourse>(pageNum,10);
			p.setTotalCount(count);
			p.setList(page);
			p.setPrePageNum(pageNum-1);
			p.setNextPageNum(pageNum+1);
			request.setAttribute("page", p);
			
			
			
				request .getRequestDispatcher("stuCourseAll.jsp").forward(request, response);
			}
			
		
		
		protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			doGet(request, response);
		}

	}